package edu.zqu.collegeField.project.controller;


import edu.zqu.collegeField.project.po.FieldDepartment;
import edu.zqu.collegeField.project.po.FieldDepartmentExamine;
import edu.zqu.collegeField.project.service.FieldDepartmentExamineService;
import edu.zqu.collegeField.project.vo.FieldDepartmentExamineVo;
import edu.zqu.collegeField.project.vo.FieldDepartmentVo;
import edu.zqu.common.result.ZQUResult;
import edu.zqu.common.status.HttpStatus;
import edu.zqu.common.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigInteger;
import java.util.List;

/**
 * <p>
 * 场地申请部门审核结果 前端控制器
 * </p>
 *
 * @author 廖森
 * @since 2020-06-28
 */
@RestController
@RequestMapping("/fieldDepartmentExamine")
@Api(tags = "场地申请部门审核结果")
public class FieldDepartmentExamineController {
    @Autowired
    private FieldDepartmentExamineService fieldDepartmentExamineService;

    @ApiOperation(value = "获取场地申请部门审核结果列表")
    @GetMapping(value = "/fieldDepartmentExamines")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "collegeId", value = "学校id", paramType = "query", required = true),
            @ApiImplicitParam(name = "fieldApplicationId", value = "场地申请id", paramType = "query", required = false),
            @ApiImplicitParam(name = "departmentId", value = "部门id", paramType = "query", required = false)
    })
    public ZQUResult get(BigInteger collegeId,
                         BigInteger fieldApplicationId,
                         BigInteger departmentId
    ) {
        List<FieldDepartmentExamineVo> fieldDepartmentExamineVoList = fieldDepartmentExamineService.get(collegeId, fieldApplicationId, departmentId);
        if (StringUtils.isNotEmpty(fieldDepartmentExamineVoList)) {
            return new ZQUResult(HttpStatus.SUCCESS, "请求成功", fieldDepartmentExamineVoList);
        } else return new ZQUResult(HttpStatus.NO_CONTENT, "请求失败",null);
    }

    @ApiOperation(value = "获取场地申请部门审核结果信息", response = FieldDepartmentExamineVo.class)
    @GetMapping(value = "/fieldDepartmentExamine/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "场地申请部门审核结果id", paramType = "path", required = true)
    })
    public ZQUResult getById(@PathVariable BigInteger id) {
        FieldDepartmentExamineVo fieldDepartmentExamineVo = fieldDepartmentExamineService.getById(id);
        if (StringUtils.isNotNull(fieldDepartmentExamineVo)) {
            return new ZQUResult(HttpStatus.SUCCESS, "请求成功", fieldDepartmentExamineVo);
        }
        return new ZQUResult(HttpStatus.NO_CONTENT, "请求失败",null);
    }

    @ApiOperation(value = "添加")
    @PostMapping(value = "/fieldDepartmentExamine")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "FieldDepartmentExamine", name = "FieldDepartmentExamine", value = "场地申请部门审核结果对象", paramType = "query", required = true)
    })
    public ZQUResult add(@RequestBody FieldDepartmentExamine fieldDepartmentExamine) {
        int rs = fieldDepartmentExamineService.add(fieldDepartmentExamine);
        if (rs >= 1) {
            return new ZQUResult(HttpStatus.SUCCESS, "添加成功",null);
        }
        return new ZQUResult(HttpStatus.ERROR, "添加失败",null);
    }

    @ApiOperation(value = "更新")
    @PutMapping(value = "/fieldDepartmentExamine")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "FieldDepartmentExamine", name = "FieldDepartmentExamine", value = "场地申请部门审核结果对象", paramType = "query", required = true)
    })
    public ZQUResult update(@RequestBody FieldDepartmentExamine fieldDepartmentExamine) {
        int rs = fieldDepartmentExamineService.update(fieldDepartmentExamine);
        if (rs >= 1) {
            return new ZQUResult(HttpStatus.SUCCESS, "修改成功",null);
        }
        return new ZQUResult(HttpStatus.ERROR, "修改失败",null);
    }

    @ApiOperation(value = "删除")
    @DeleteMapping(value = "/fieldDepartmentExamine/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "场地申请部门审核结果id", paramType = "path", required = true),
            @ApiImplicitParam(name = "byWho", value = "用户id", paramType = "query", required = true)
    })
    public ZQUResult delete(@PathVariable BigInteger id, BigInteger byWho) {
        int rs = fieldDepartmentExamineService.delete(id, byWho);
        if (rs >= 1) {
            return new ZQUResult(HttpStatus.SUCCESS, "删除成功",null);
        }
        return new ZQUResult(HttpStatus.ERROR, "删除失败",null);
    }
}

